from representation import representation, Melody, Note, Measure
from music_data import *
rep_obj = representation("C", 180, False, True, None)
measure_list = []
melody_list = []
t = 0
filename = input()
with open('rawtxt/'+filename, "r") as f:
    for l in f:
        l = l.split()
        if len(l)==0:
            continue
        t += float(l[1])
        if l[0] == 'Rest':
            measure_list.append(Note(NOTE_TO_MIDI[l[0]], float(l[1]), int(l[2])))
        else:
            measure_list.append(Note(NOTE_TO_MIDI[l[0]]-12, float(l[1]), int(l[2])))
        if abs(t - 4.0) <= 1e-4:
            t = 0
            melody_list.append(Measure(measure_list))
            measure_list = []
melody = Melody("C", melody_list)
rep_obj.melody_to_midi(melody, 'database/'+filename[:-4]+'.mid', True)
